﻿package view
{
    import __AS3__.vec.*;
    import cmd.*;
    import com.core.*;
    import com.greensock.*;
    import com.sh.game.consts.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;

    public class ChatTip extends Sprite
    {
        private var _union:Sprite;
        private var _private:Sprite;
        private var _friend:Sprite;
        private var _chatDic:Dictionary;
        private var _isInit:Boolean = false;
        private var _isIniting:Boolean = false;
        private var _delayMsg:Object;
        private var _friendList:Array;
        private var _moveTime:int = 0;
        private var iconPrivate:Image;
        private var iconUnion:Image;
        private var iconFriend:Image;
        private var imgAlp:Number = 1;
        private var speed:Number = 0.05;
        private var glow:Boolean = true;
        private var _showList:Array;
        private var _unionLight:Boolean = true;
        private var _privateLight:Boolean = true;

        public function ChatTip()
        {
            this._chatDic = new Dictionary();
            this._delayMsg = [[], [], []];
            this._friendList = [];
            this._showList = [];
            this.addEventListener(MouseEvent.CLICK, this.doMouse);
            return;
        }// end function

        public function updateAdd(param1:int, param2:Object) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Array = null;
            var _loc_5:Array = null;
            var _loc_6:Boolean = false;
            var _loc_7:Vector.<Object> = null;
            var _loc_8:String = null;
            if (param1 == 3)
            {
                _loc_3 = UserData.getUserData();
                _loc_4 = ["小样，在去多练几年吧！！这么脆怎么出去混啊，O(∩_∩)O", "手抖了一下，哈哈，对不起啊！O(∩_∩)O", "不小心两下搞死了你，发现你装备还不行哦，你可以去看看角色面板的战斗力提升方法提升一下，看好你哦，加油！O(∩_∩)O", "啊~不好意思，模式没改好，阿弥陀佛善哉善哉~", "真的，我一不小心手一抖你就挂B了，不能怪我吧~"];
                _loc_5 = [param2.rid, param2.name, 0, _loc_3.rid, _loc_3.name, 0, 0, _loc_4[int(Math.random() * 5)], param2.sex, param2.career, param2.rein, param2.level];
                ModelProxy.change("movetips", "error", "你被玩家" + param2.name + "杀死了");
                param2 = _loc_5.join("#!");
                param1 = 0;
                _loc_6 = ModelProxy.getValue("data", "simpleChatIsInit");
                if (!_loc_6)
                {
                    _loc_7 = ModelProxy.getValue("data", "simpleChatMsg");
                    if (!_loc_7)
                    {
                        _loc_7 = new Vector.<Object>;
                    }
                    _loc_7.push({cmd:6, msg:param2});
                    ModelProxy.change("data", "simpleChatMsg", _loc_7);
                }
                else
                {
                    ModelProxy.change("chat", "normalmsg", {cmd:ChatCMD.ChannelPrivate, msg:param2});
                }
            }
            switch(param1)
            {
                case 0:
                {
                    break;
                }
                case 1:
                {
                    break;
                }
                case 2:
                {
                    break;
                }
                default:
                {
                    break;
                }
            }
            if (!this._isIniting)
            {
            }
            return;
        }// end function

        public function updateRemove(param1:int) : void
        {
            if (!this._isIniting)
            {
                return;
            }
            switch(param1)
            {
                case 0:
                {
                    this._private.visible = false;
                    break;
                }
                case 1:
                {
                    this._union.visible = false;
                    break;
                }
                case 2:
                {
                    this._friend.visible = false;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function onComp(param1:Object) : void
        {
            var _loc_2:Object = null;
            this.initShow();
            if (this._delayMsg[0].length > 0)
            {
                for each (_loc_2 in this._delayMsg[0])
                {
                    
                    this.addPrivate(_loc_2);
                }
            }
            if (this._delayMsg[1].length > 0)
            {
                this.addUnion(this._delayMsg[1][0]);
            }
            if (this._delayMsg[2].length > 0)
            {
                for each (_loc_2 in this._delayMsg[2])
                {
                    
                    this.addFriend(_loc_2);
                }
            }
            this._isInit = true;
            return;
        }// end function

        private function initShow() : void
        {
            var _loc_1:* = new Sprite();
            this._private = new Sprite();
            this.addChild(_loc_1);
            var _loc_1:* = new Sprite();
            this._union = new Sprite();
            this.addChild(_loc_1);
            var _loc_1:* = new Sprite();
            this._friend = new Sprite();
            this.addChild(_loc_1);
            this._private.name = "private";
            this._union.name = "union";
            this._friend.name = "friend";
            var _loc_1:Boolean = false;
            this._friend.visible = false;
            var _loc_1:* = _loc_1;
            this._union.visible = _loc_1;
            this._private.visible = _loc_1;
            this.iconPrivate = new Image("png.common.cs2unionchattips");
            this._private.addChild(this.iconPrivate);
            this.iconUnion = new Image("png.common.cs2prichattips");
            this._union.addChild(this.iconUnion);
            this.iconFriend = new Image("png.common.cs2prichattips");
            this._friend.addChild(this.iconFriend);
            var _loc_1:Boolean = false;
            this._friend.mouseChildren = false;
            var _loc_1:* = _loc_1;
            this._union.mouseChildren = _loc_1;
            this._private.mouseChildren = _loc_1;
            this._private.addEventListener(MouseEvent.CLICK, this.doMouse);
            this._union.addEventListener(MouseEvent.CLICK, this.doMouse);
            this._friend.addEventListener(MouseEvent.CLICK, this.doMouse);
            this._private.addEventListener(MouseEvent.MOUSE_OVER, this.doMouse);
            this._union.addEventListener(MouseEvent.MOUSE_OVER, this.doMouse);
            this._friend.addEventListener(MouseEvent.MOUSE_OVER, this.doMouse);
            this._private.addEventListener(MouseEvent.MOUSE_OUT, this.doMouse);
            this._union.addEventListener(MouseEvent.MOUSE_OUT, this.doMouse);
            this._friend.addEventListener(MouseEvent.MOUSE_OUT, this.doMouse);
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.doStop);
            return;
        }// end function

        protected function doMouse(event:MouseEvent) : void
        {
            var _loc_2:* = event.target.name;
            switch(_loc_2)
            {
                case "union":
                {
                    switch(event.type)
                    {
                        case MouseEvent.CLICK:
                        {
                            PluginManager.instance.openPlugin("unionChat", UIGlobel.pointsDic["social"], null);
                            this._union.visible = false;
                            this.checkClose(this._union);
                            break;
                        }
                        case MouseEvent.MOUSE_OVER:
                        {
                            ModelProxy.change("tips", "normal", "帮会：帮会聊天");
                            break;
                        }
                        case MouseEvent.MOUSE_OUT:
                        {
                            ModelProxy.change("tips", "state", "close");
                            break;
                        }
                        default:
                        {
                            break;
                        }
                    }
                    break;
                }
                case "private":
                {
                    switch(event.type)
                    {
                        case MouseEvent.CLICK:
                        {
                            PluginManager.instance.openPlugin("simpleChat", UIGlobel.pointsDic["social"], this._chatDic);
                            this._private.visible = false;
                            this.checkClose(this._private);
                            break;
                        }
                        case MouseEvent.MOUSE_OVER:
                        {
                            ModelProxy.change("tips", "normal", "私聊：私人聊天");
                            break;
                        }
                        case MouseEvent.MOUSE_OUT:
                        {
                            ModelProxy.change("tips", "state", "close");
                            break;
                        }
                        default:
                        {
                            break;
                        }
                    }
                    break;
                }
                case "friend":
                {
                    switch(event.type)
                    {
                        case MouseEvent.CLICK:
                        {
                            this._friendList = [];
                            this._friend.visible = false;
                            this.checkClose(this._friend);
                            break;
                        }
                        case MouseEvent.MOUSE_OVER:
                        {
                            ModelProxy.change("tips", "normal", "好友：好友请求");
                            break;
                        }
                        case MouseEvent.MOUSE_OUT:
                        {
                            ModelProxy.change("tips", "state", "close");
                            break;
                        }
                        default:
                        {
                            break;
                        }
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        protected function doStop(event:MouseEvent) : void
        {
            return;
        }// end function

        public function addUnion(param1:Object) : void
        {
            var _loc_2:Array = null;
            if (param1)
            {
                _loc_2 = param1.split("#!");
                this._unionLight = true;
            }
            else
            {
                this._unionLight = false;
            }
            if (!this._union.visible)
            {
                this._union.visible = true;
                this._showList.unshift(this._union);
                this.doTween();
            }
            this.checkTime();
            return;
        }// end function

        private function checkClose(param1:Sprite) : void
        {
            var _loc_2:* = this._showList.length - 1;
            while (_loc_2 >= 0)
            {
                
                if (this._showList[_loc_2] == param1)
                {
                    this._showList.splice(_loc_2, 1);
                    this.doTween();
                    break;
                }
                _loc_2 = _loc_2 - 1;
            }
            param1.y = 0;
            if (this._moveTime != 0)
            {
                if (!this._union.visible && !this._private.visible && !this._friend.visible)
                {
                    clearInterval(this._moveTime);
                    this._moveTime = 0;
                }
            }
            return;
        }// end function

        private function checkTime() : void
        {
            if (this._moveTime == 0)
            {
                this.imgAlp = 1;
                this._moveTime = setInterval(this.doAnimate, 500);
            }
            return;
        }// end function

        private function doAnimate() : void
        {
            if (this.glow)
            {
                if (this._privateLight)
                {
                    this.iconPrivate.filters = [new GlowFilter(13772713, 1, 10, 10)];
                }
                if (this._unionLight)
                {
                    this.iconUnion.filters = [new GlowFilter(5683512, 1, 10, 10)];
                }
                this.iconFriend.filters = [new GlowFilter(5220315, 1, 10, 10)];
                this.glow = false;
            }
            else
            {
                var _loc_1:String = null;
                this.iconUnion.filters = null;
                var _loc_1:* = _loc_1;
                this.iconPrivate.filters = _loc_1;
                this.iconFriend.filters = _loc_1;
                this.glow = true;
            }
            return;
        }// end function

        public function addPrivate(param1:Object) : void
        {
            var _loc_2:Array = null;
            var _loc_3:Object = null;
            var _loc_4:Array = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            if (param1)
            {
                _loc_2 = param1.split("#!");
                if (_loc_2[0] == UserData.getUserData("rid"))
                {
                    return;
                }
                if (_loc_2[0] > 0)
                {
                    _loc_4 = ModelProxy.getValue("data", "heilist");
                    if (_loc_4 && _loc_4.length > 0)
                    {
                        _loc_5 = 0;
                        _loc_6 = _loc_4.length;
                        _loc_5 = 0;
                        while (_loc_5 < _loc_6)
                        {
                            
                            if (_loc_2[0] == _loc_4[_loc_5])
                            {
                                return;
                            }
                            _loc_5++;
                        }
                    }
                }
                _loc_3 = {rid:_loc_2[0], name:_loc_2[1], sex:_loc_2[8], career:_loc_2[9], rein:_loc_2[10], level:_loc_2[11]};
                this._chatDic[_loc_2[0]] = _loc_3;
                this._privateLight = true;
            }
            else
            {
                this._privateLight = false;
            }
            if (!this._private.visible)
            {
                this._private.visible = true;
                this._showList.unshift(this._private);
                this.doTween();
            }
            this.checkTime();
            return;
        }// end function

        public function addFriend(param1:Object) : void
        {
            var _loc_2:Object = null;
            var _loc_3:Boolean = false;
            var _loc_4:Object = null;
            for each (_loc_2 in param1)
            {
                
                _loc_3 = false;
                for each (_loc_4 in this._friendList)
                {
                    
                    if (_loc_4.rid == _loc_2.rid)
                    {
                        _loc_3 = true;
                        break;
                    }
                }
                if (_loc_3)
                {
                    continue;
                }
                this._friendList.push(_loc_2);
            }
            if (!this._friend.visible)
            {
                this._friend.visible = true;
                this._showList.unshift(this._friend);
                this.doTween();
            }
            this.checkTime();
            return;
        }// end function

        private function doTween() : void
        {
            var _loc_1:* = this._showList.length - 1;
            while (_loc_1 >= 0)
            {
                
                TweenLite.to(this._showList[_loc_1], 1, {x:0, y:_loc_1 * -30});
                _loc_1 = _loc_1 - 1;
            }
            return;
        }// end function

        public function updateChange(param1:int, param2:Object) : void
        {
            switch(param1)
            {
                case 1:
                {
                    delete this._chatDic[param2];
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
